<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>

<chiptrack:checkLogon sourcePage="/costReportAction.do?action=standardCostReport" />

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); /*try {*/ %>
<HTML>
    <HEAD>
        <TITLE>Scalarsoft - ChipTrac</TITLE>
        <META http-equiv=Content-Type content="text/html; charset=windows-1252">
        <LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
        <SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
        <SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
        <SCRIPT>
            var dateElement = "";
            function openCalendar(dateValue)
            {
                dateElement = dateValue;
                newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
                newWindow.moveTo(550,180);
                newWindow.focus();
            }
            function assignDate(passedValue)
            {
                dateElement.value=passedValue;
                window.focus();
            }
            function loadDetails(fromValue)
            {
                var form = document.costReportsForm;
                var reportType;
                for ( var i = 0; i < form.reportType.length; i++ )
                {
                    if ( form.reportType[i].checked )
                    {
                        reportType = form.reportType[i].value;
                        break;
                    }
                }
                
                var asOfDatelabel = document.getElementById("AsOfDate");
                if ( fromValue != 1 && reportType != 'stdcostsummary' )
                {
                    form.processTypeName.disabled = false;
                    if ( reportType == 'prjcostdetail' )
                    {
                        //alert("form.fromDate.");
                        //form.fromDate.disabled = true;
                        form.fromDate.style.visibility = "hidden";
                        form.pickdate.style.visibility = "hidden";
                        asOfDatelabel.innerHTML = "";
                    }
                    else
                    {
                        form.fromDate.style.visibility = "visible";
                        form.pickdate.style.visibility = "visible";
                        asOfDatelabel.innerHTML = "As of Date";
                    }
                }
                else
                {
                    form.action = "<%=chipTracContext%>/costReportAction.do?action=standardCostReport";
                    form.submit();
                }
            }

            <%--function disablefields()
            {
                var form = document.costReportsForm;
                form.action = "<%=chipTracContext%>/costReportAction.do?action=standardCostReport";
                form.submit();
            }
            --%>
            function validateFromAndToDates()
            {
                var form = document.costReportsForm;
                errMsg = '';
                var errors = '';
                var pa	= document.getElementById("errors");
                var infoMessages = document.getElementById("infoMessagesId");
                var errorMessages = document.getElementById("errorMessagesId");
                infoMessages.innerHTML = '';
                errorMessages.innerHTML = '';

                if ( errors != '' )
                {
                    pa.innerHTML = errors;
                    return false;
                }
                return true;
            }

            function Disab()
            {
                var formdoc = document.costReportsForm;

                var reportType = "";
                
                for ( var i = 0; i < formdoc.reportType.length; i++ )
                {    
                    if ( formdoc.reportType[i].checked )
                    {
                        reportType = formdoc.reportType[i].value;
                        break;
                    }
                }

                if ( reportType == 'stdcostsummary' )
                {
                    formdoc.processTypeName.disabled = true;
                }
            }

            function submitPage( fileType )
            {
                var formdoc = document.costReportsForm;

                if ( validateFromAndToDates() )
                {
                    var d = new Date();
                    var day = d.getDate();
                    var month = d.getMonth()+1;
                    var year = d.getFullYear();
                    var hour = d.getHours();
                    var min = d.getMinutes();
                    var sec = d.getSeconds();
                    if ( month < 10 )
                    month = "0"+month;
                    if ( day < 10 )
                    day = "0"+day;
	                var today = month+"/"+day+"/"+year;
                    var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;

                    var reportType = "";

                    for ( var i = 0; i < formdoc.reportType.length; i++ )
                    {
                        if ( formdoc.reportType[i].checked )
                        {
                            reportType = formdoc.reportType[i].value;
                            break;
                        }
                    }

                    var partNumberObj = formdoc.processStepId;
                    var processstepId = "";
                    var count = 0;
                    for( var i = 0; i < partNumberObj.length; i++ )
                    {
                        if( partNumberObj.options[i].selected )
                        {
                            count++;
                            if ( processstepId != '' )
                            {
                                processstepId = processstepId + "," + partNumberObj.options[i].value;
                            }
                            else
                            {
                                processstepId = partNumberObj.options[i].value;
                                if( partNumberObj.options[i].value == '0' )
                                {
                                    break;
                                }
                            }
                        }
                    }
                    if ( processstepId == '')
                    {
                        processstepId = "0";
                    }
                    if( count > 10)
                    {
                        pa.innerHTML = "<li>Please select upto 10 Products only";
                        return;
                    }

                    if ( reportType == 'stdcostdetail' || reportType == 'prjcostdetail' )
                    {
                        formdoc.prompt0.value  = formdoc.processTypeName.value;
                        formdoc.prompt1.value  = '0';
                        formdoc.prompt2.value  = processstepId;
                        formdoc.prompt3.value  = formdoc.vendorId.value;
                        formdoc.prompt4.value  = formdoc.fromDate.value.trim();
                        if ( formdoc.prompt4.value == null || formdoc.prompt4.value=='' || formdoc.prompt4.value == today )
                        {
                            formdoc.prompt4.value='0';
                        }

                        formdoc.prompt5.value  = reportType;
                        formdoc.prompt6.value  = defaultPrompt;

                        if ( reportType == 'stdcostdetail' && fileType == 1 )
                        {
                            formdoc.prompt7.value  = 'Crystal';
                            formdoc.action = "<%=chipTracContext%>/jsp/report.jsp?nameReport=Finance/New_Cost/Standard_Cost_Report.rpt";
                        }
                        else
                        {
                            formdoc.prompt7.value  = 'xlreport';
                            formdoc.action = "<%=chipTracContext%>/costReportAction.do?action=xlsdetailCostReport";
                        }
                    }
                    else //if ( reportType == 'stdcostsummary' )
                    {
                        formdoc.prompt0.value  = processstepId;
                        formdoc.prompt1.value  = formdoc.vendorId.value;
                        formdoc.prompt2.value  = formdoc.fromDate.value.trim();
                        if ( formdoc.prompt2.value == null || formdoc.prompt2.value=='' || formdoc.prompt2.value == today )
                        {
                            formdoc.prompt2.value='0';
                        }

                        formdoc.prompt3.value  = '0';
                        formdoc.prompt4.value  = '0';
                        formdoc.prompt5.value  = '0';
                        formdoc.prompt6.value  = defaultPrompt;

                        formdoc.action = "<%=chipTracContext%>/jsp/report.jsp?nameReport=Finance/New_Cost/Inventory_Summary_Cost_Report.rpt";
                    }

                    formdoc.submit();
                }
            }
        </SCRIPT>
    </HEAD>
    <BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="javascript:Disab()">

    <!-- Top Header Start-->
    <%@ include file="/jsp/includes/header.jsp" %>
    <!-- Top Header End-->

    <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
      <TBODY>
      <TR>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

        <!-- Side Navigation start -->
        <%@ include file="/jsp/finance/finance_reports_menu.jsp" %>
        <!-- end of the side navigations -->
    <TD bgcolor="#ffffff">
    <IMG height=9 src="images/spacer.gif" width=8></TD>
    <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
    <TD valign="top" width="100%">

    <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
    <BR>
    <!-- from here your body starts -->
    <center><span class="NArialW">Standard Cost Report</span></center>
    <!--<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5>-->
    <html:form action="/costReportAction" name="costReportsForm" type="com.scalar.chiptrack.finance.forms.CostReportsForm">
        <input type="hidden" name="prompt0">
        <input type="hidden" name="prompt1">
        <input type="hidden" name="prompt2">
        <input type="hidden" name="prompt3">
        <input type="hidden" name="prompt4">
        <input type="hidden" name="prompt5">
        <input type="hidden" name="prompt6">
        <input type="hidden" name="prompt7">
        <input type="hidden" name="prompt8">
        <input type="hidden" name="prompt9">
        <input type="hidden" name="prompt10">
        <TABLE BORDER="0" WIDTH="90%" ALIGN=RIGHT>
            <TR>
                <TD colspan="5" align="right"><FONT class="NArialL"><B><A href="<%=chipTracContext%>/costReportAction.do?action=calculateCost"
                    title="Click to update inventory costs" onMouseOver="window.status='Click to update inventory costs';return true"
                    onmouseout="window.status='';return true">Update inventory costs</A></B></FONT></TD>
            </TR>
            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></TD></TR>
            <TR>
                <TD colspan = "5"><FONT id="errors" class="NArialL" color='FF0000'>&nbsp;</FONT></TD>
            <TR>
            <TR><TD colspan='5' id='errorMessagesId'><chiptrack:errors styleClass='NArialL' /></TD></TR>
            <TR><TD colspan='5' id='infoMessagesId'><chiptrack:info styleClass='NArialL' /> </TD></TR>
            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></TD></TR>
            <TR>
                <TD WIDTH="15%" CLASS="NArialL">Process Type</TD>
                <TD WIDTH="20%" CLASS="NArialL">
                    <nested:select property="processTypeName" styleClass="txfield" onchange="javascript:loadDetails(1)">
                        <nested:options collection="processTypeNameList" property="value" labelProperty="label"/>
                    </nested:select>
                </TD>
                <TD WIDTH="10%">&nbsp;</TD>
                <TD WIDTH="13%" CLASS="NArialL" nowrap>Base Product </TD>
                <TD WIDTH="20%" CLASS="NArialL">
                    <nested:select property="processStepId" styleClass="txfield" multiple="true" size="5" >
                        <html:option value="0">All Part Numbers</html:option>
                        <nested:options collection="partNumberList" property="value" labelProperty="label"/>
                    </nested:select>
                </TD>
                <TD WIDTH="10%">&nbsp;</TD>
            </TR>
            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></TD></TR>
            <TR>
                <TD WIDTH="15%" CLASS="NArialL">Vendor</TD>
                <TD WIDTH="20%" CLASS="NArialL">
                    <nested:select property="vendorId" styleClass="txfield">
                        <nested:options collection="vendorList" property="value" labelProperty="label"/>
                    </nested:select>
                </TD>

                <TD WIDTH="10%">&nbsp;</TD>

                <TD WIDTH="13%" CLASS="NArialL" id="AsOfDate" >As of Date</TD>
                <TD WIDTH="20%" CLASS="NArialL" >
                    <nested:text property="fromDate" size="10" styleClass="txfield"/>&nbsp;
		            <A  href="javascript:openCalendar(document.costReportsForm.fromDate)">
		            <IMG name="pickdate" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height="20" width="20" border="0" onmouseover="window.status='Click to Select Date';return true" onmouseout="window.status='';return true"></A>
                </TD>

                <TD WIDTH="10%">&nbsp;</TD>
            </TR>
            <TR><TD colspan='6'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></TD></TR>
            <TR>
                <TD width="15%" class=NArialL >
                   <nested:radio name="costReportsForm" property="reportType" value="stdcostsummary" onclick="loadDetails(2)">Summary</nested:radio>
                </TD>
                <TD width="20%" class=NArialL >
                    <nested:radio name="costReportsForm" property="reportType" value="stdcostdetail" onclick="loadDetails(2)">Detail</nested:radio>
                </TD>
                <TD width="20%" class=NArialL >
                    <nested:radio name="costReportsForm" property="reportType" value="prjcostdetail" onclick="loadDetails(2)">Detail Projected Cost</nested:radio>
                </TD>
                <TD width="3%">&nbsp;</TD>
                <TD width="20%">&nbsp;</TD>
                <TD width="10%">&nbsp;</TD>
            </TR>
            <TR>
                <TD colspan='4'>&nbsp;</TD>
                <TD width="20%" class=NArialL><a href="javascript:submitPage(2);" class="leftsection" onMouseOver="window.status='Click to Export Cost Information';return true" onmouseout="window.status='';return true">Export to Excel</a></TD>
                <TD width="10%">&nbsp;</TD>
            </TR>

            <TR>
                 <TD colspan='6'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></TD>
            </TR>

            <TR>
                <TD COLSPAN=5 align="center">
                    <A href="javascript:submitPage(1);" onMouseOver="window.status='Click to Generate Standard Cost Report ';return true" onMouseOut="window.status='';return true" title= "Click here to Generate Standard Cost Report ">
                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17"></A>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:document.costReportsForm.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border='0' onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
                </TD>
            </TR>
        </TABLE>
    </html:form>
    <!-- till here -->
    <BR><BR><BR></TD>
    <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
    </TABLE>
    <!-- Footer starts here -->
    <%@ include file="/jsp/includes/footer.jsp" %>
    <!-- footer end here -->
    </BODY>
</HTML>
<%--
<% }catch(Exception e){e.printStackTrace();} %>--%>
